package com.proyectos.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import javax.faces.bean.ManagedBean;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 *
 * @author Jose
 */
@Entity
@ManagedBean

@NamedQueries({
    @NamedQuery(name = "Carreras.findByName", query = "SELECT c FROM Carreras c WHERE upper(c.cnombre) like :cnombre"),
    @NamedQuery(name = "Carreras.findByCodigo", query = "SELECT c FROM Carreras c WHERE upper(c.ccodigo) = :ccodigo"),
    @NamedQuery(name = "Carreras.findAll", query = "SELECT c FROM Carreras c")})
public class Carreras implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column
    private BigDecimal ncodigo;
    @Column
    private String cnombre;
    @Column
    private String ccampus;
    @Column
    private String ccodigo;
    @Column
    private String cpassword;
    @Column
    private String ccoordinador;
    @Column
    private String cdespacho;
    @Column
    private String cmail;
    @Column
    private String ctelefono;
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH, mappedBy = "ncarrera")
    private List<Cursos> listaCur;

    public Cursos getCursoActivo() {
        if (listaCur != null) {
            for (Cursos cur : this.listaCur) {
                if (cur.getActivo().equals("Y"))
                    return cur;
            }
        } else {
            return null;
        }
        return null;
    }

    public String getCcoordinador() {
        return ccoordinador;
    }

    public void setCcoordinador(String ccoordinador) {
        this.ccoordinador = ccoordinador;
    }

    public String getCtelefono() {
        return ctelefono;
    }

    public void setCtelefono(String ctelefono) {
        this.ctelefono = ctelefono;
    }

    public String getCdespacho() {
        return cdespacho;
    }

    public void setCdespacho(String cdespacho) {
        this.cdespacho = cdespacho;
    }

    public String getCmail() {
        return cmail;
    }

    public void setCmail(String cmail) {
        this.cmail = cmail;
    }

    public String getCpassword() {
        return cpassword;
    }

    public void setCpassword(String cpassword) {
        this.cpassword = cpassword;
    }

    public String getCcodigo() {
        return ccodigo;
    }

    public void setCcodigo(String ccodigo) {
        this.ccodigo = ccodigo;
    }

    public BigDecimal getNcodigo() {
        return ncodigo;
    }

    public void setNcodigo(BigDecimal ncodigo) {
        this.ncodigo = ncodigo;
    }

    public String getCnombre() {
        return cnombre;
    }

    public void setCnombre(String cnombre) {
        this.cnombre = cnombre;
    }

    public String getCcampus() {
        return ccampus;
    }

    public void setCcampus(String ccampus) {
        this.ccampus = ccampus;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 37 * hash + Objects.hashCode(this.ccodigo);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Carreras other = (Carreras) obj;
        if (!Objects.equals(this.ccodigo, other.ccodigo)) {
            return false;
        }
        return true;
    }
}
